<?php


namespace app\api\controller;


use app\api\logic\CartLogic;
use app\api\validate\CartValidate;
use app\common\controller\BaseApiController;

/**
 * 购物车
 * Class CartController
 * @package app\api\controller
 */
class CartController extends BaseApiController
{
    protected $noNeedLogin = [
        'count'
    ];

    protected function init()
    {
        parent::init();
        $this->validate = new CartValidate();
        $this->logic = new CartLogic();
    }


    public function edit()
    {
        $this->validate->checkData(input(), 'edit');
        $this->logic->editCart(input());
        return $this->success();
    }

    public function add()
    {
        $this->validate->checkData(input(), 'add');
        $this->logic->addCart(input());
        return $this->success();
    }

    public function list()
    {
        return $this->success($this->logic->listCart());
    }

    public function deleteSku()
    {
        $this->validate->checkData(input(), 'deleteSku');
        return $this->success($this->logic->deleteSku(input("goods_id"), input("sku_id")));
    }

    public function clear()
    {
        return $this->success($this->logic->deleteCart());
    }

    public function count()
    {
        if (request()->uid) {
            return $this->success($this->logic->cartCount());
        }
        return $this->success(0);
    }
}